﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Runtime.InteropServices;
using Models;

namespace DAL
{
    public class D_G
    {
        public List<Models.g_data> getList()
        {
            var list = Sugar_helper.Db.Queryable<Models.g_data>().ToList();
            return list;
        }

        public bool save_result(List<g_data> gs)
        {
            var count = Sugar_helper.Db.Storageable<g_data>(gs).ExecuteCommand();
            return count==gs.Count? true: false;
        }

        public int commit_suger(g_data model)
        {
            var count = Sugar_helper.Db.Storageable(model).ExecuteCommand();
            return count;
        }

        public Models.g_data select(Models.Student student)
        {
            var m_g = Sugar_helper.Db.Queryable<g_data>().Where(g=>g.g_id==student.group_id).ToList();
            if(m_g.Count > 0)
                return m_g[0];
            else return null;
        }

        public bool Del(Stu_group stu_Group)
        {
            var res = Sugar_helper.Db.Deleteable<g_data>().Where(g => g.g_id == stu_Group.group_id).ExecuteCommand();
            return res == 1 ? true : false;
        }
    }
}
